package prictise.com.application1.suanFa;

public class FibonacciTest {
  
  public static int fm(int n) {
    if (n < 0) {
      return 0;
    }
    if (n == 1 || n == 2) {
      return 1;
    } else {
      return fm(n - 1) + fm(n - 2);
    }
  }
  
  public static int fm2(int n) {
    if (n < 0) {
      return 0;
    }
    int result = 0;
    
    int first = 1;
    int second = 1;
    
    for (int i = 2; i < n; i++) {
      result = first + second;
      first = second;
      second = result;
    }
    
    return result;
  }
}
